<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
%>
<html>
<head>

<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/icon.css">
	<link href="<%=path%>/css/zzsc.css" type="text/css" rel="stylesheet" />
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/ueditor.all.min.js">
</script>

<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">

	if (top.location != self.location)
		top.location = self.location;

	$(function() {
		//如果该值不为空，则表示其他用户访问，需要把上次浏览按钮禁用
		var otherMaker = '${otherMaker}';
		if(otherMaker!=null && otherMaker!=""){
			$("#shagnciBtn").css("visibility","hidden");
		}
		
		$('#p').panel({
			width : 1000,
			height : 600,
			title : '${xiaoshuo.filename}'
		});
		
		$('#pizhu').window('minimize'); 
		
		$("#p").mouseup(function (e) {
			var txt;
			var parentOffset = $(this).offset();
			var x = e.pageX - parentOffset.left;
			var y = e.pageY - parentOffset.top;
			txt = window.getSelection();
		    
			if (txt.toString().length > 1) {
				var selected = txt.toString();
				$('#mm').menu('show', {    
					  left: x,    
					  top: y    
					});  
			
				if(otherMaker!=null && otherMaker!="" ){
		    		$('#mm').menu('removeItem',$(".saveShuqianDiv"));
		    		$('#mm').menu('removeItem',$(".pizhuDiv"));
		    	}
				
				
				$('#mm').menu({    
				    onClick:function(item){    
				    	
				    	if(item.text=="保存书签"){
				    		
				    		   $.ajax({
						                type: "POST",//方法类型
						                dataType: "json",//预期服务器返回的数据类型
						                url: "<%=path%>/xiaoshuoAction/saveShuqian",
						                data: {
						                	selected:selected,
						                	xiaoshuoId:'${xiaoshuo.id}'
						                	
						                },
						                success: function (result) {
						                    
						                	$.messager.alert('提示',result.msg); 
						                },
						                error : function() {
						                    alert("系统异常！");
						                }
						            });
				    		
				    	}else if(item.text=="批注"){
				    		$("#pizhu").css("visibility","visible");
				    		$("#pizhuContent").val("");
				    		$("#selectedContent").val(selected);
				    		$('#pizhu').window({    
				    		    width:219,    
				    		    height:165,    
				    		    modal:true,
				    		    left:x,
				    		    top:y
				    		});  
				    	}else if(item.text=="显示批注"){
				    		$("#pizhu").css("visibility","visible");
				    		$("#selectedContent").val(selected);
				    		   $.ajax({
					                type: "POST",//方法类型
					                dataType: "json",//预期服务器返回的数据类型
					                url: "<%=path%>/xiaoshuoAction/getPizhu",
					                data: {
					                	selected:selected,
					                	xiaoshuoId:'${xiaoshuo.id}',
					                	otherUserId:'${otherUserId}'
					                	
					                },
					                success: function (result) {
					                    
					                	if(result.errMsg!=null && result.errMsg!=""){
					                		$.messager.alert('警告',result.errMsg);  
					                		
					                	}else{
					                		if(result.pizhu!=null){
						                		$("#pizhuContent").val(result.pizhu.content);
						                		$('#pizhu').window({    
									    		    width:219,    
									    		    height:165,    
									    		    modal:true,
									    		    left:x,
									    		    top:y
									    		});  
						                	}
						                	
						                	if(result.otherUserId!="" && result.otherUserId!=null){
						                		//说明是其它用户查看批注，需要禁用修改批注的按钮
						                		$("#fabiaoBtn").css("visibility","hidden");
						                		otherMaker = result.otherUserId;
						                	}
					                	}
					                	
					                
					                	
					                },
					                error : function() {
					                    alert("系统异常！");
					                }
					            });
				    		
				    	}
				    	
				    	
				    }    
				}); 
			}
		});
		
		$("#shagnciBtn").bind("click",function(){
			
			  $.ajax({
	                type: "POST",//方法类型
	                dataType: "json",//预期服务器返回的数据类型
	                url: "<%=path%>/xiaoshuoAction/getShuqian",
	                data: {
	                	xiaoshuoId:'${xiaoshuo.id}',
	                	otherMaker:'${otherMaker}'
	                	
	                },
	                success: function (result) {
	                    
	                	 $("#shagnciBtn").attr("href","#"+result.maoId);
	                },
	                error : function() {
	                    alert("系统异常！");
	                }
	            });
			
		});
		
		$("#fabiaoBtn").bind("click",function(){
			var pizhuContent = $("#pizhuContent").val();
			var pContent = $("#selectedContent").val();
			  $.ajax({
	                type: "POST",//方法类型
	                dataType: "json",//预期服务器返回的数据类型
	                url: "<%=path%>/xiaoshuoAction/savePizhu",
	                data: {
	                	xiaoshuoid:'${xiaoshuo.id}',
	                	content:pizhuContent,
	                	pContent:pContent
	                },
	                success: function (result) {
	                    
	                	$.messager.confirm('提示',result.msg,function(r){    
	                		$('#pizhu').window('minimize'); 
	                	});  
	                	
	                },
	                error : function() {
	                    alert("系统异常！");
	                }
	            });
			
		});
		
		
		//显示所有批注
		$("#pizhuBtn").bind("click",function(){
			
			  $.ajax({
	                type: "POST",//方法类型
	                dataType: "json",//预期服务器返回的数据类型
	                url: "<%=path%>/xiaoshuoAction/showPizhu",
	                data: {
	                	xiaoshuoid:'${xiaoshuo.id}',
	                	otherUserId:'${otherUserId}'
	                },
	                success: function (result) {
	                    
	                	if(result.newContent!=null){
	                		$("#show_content").html(result.newContent);
	                	}
	                	
	                },
	                error : function() {
	                    alert("系统异常！");
	                }
	            });
			
		});
		
		
		$("#backBtn").bind("click",function(){
			
			history.back();
			
		});
		
	});
	
</script>

</head>
<body>

	<a id="shagnciBtn" class="easyui-linkbutton" style="width: 120px; height: 32px;margin-top: 10px;margin-left: 500px">上次浏览记录</a>
	<a id="pizhuBtn" class="easyui-linkbutton" style="width: 120px; height: 32px;margin-top: 10px;margin-left: 0px">显示所有批注标记</a>
		<a id="backBtn" class="easyui-linkbutton" style="width: 120px; height: 32px;margin-top: 10px;margin-right: 200px;">返回</a>
	<div style="margin-left: 150px;" id="show">
		<form action="<%=path%>/guancangAction/saveAddxiaoshuo" method="post"
			enctype="multipart/form-data" id="form">
			<div id="p" style="padding-left: 50px;padding-right: 50px;">

				<div style="margin-top: 20px;">
					<div id="show_content">${xiaoshuo.content}</div>
				</div>


			</div>

		</form>
	</div>
<div id="mm" class="easyui-menu" style="width:120px;">   
    <div class="saveShuqianDiv">保存书签</div>   
    <div class="pizhuDiv">批注</div>  
    <div class="showPizhuDiv">显示批注</div> 
</div> 
<div id="pizhu"  class="easyui-window" title="批注"  style="width:219px;height:165px;"   
        data-options="modal:true,draggable:false,resizable:false,minimizable:false,maximizable:false,collapsible:true">   
   <textarea rows="6" cols="26" name="pizhu" id="pizhuContent"></textarea>
   <a id="fabiaoBtn" class="easyui-linkbutton"
					data-options="iconCls:'icon-ok'" style="margin-left: 70px;">发表</a>
</div>  
<input type="hidden" id="selectedContent">
</body>

</html>